package com.ruoyi.common.dict;

import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @program:
 * @description:
 * @author: hyq
 * @create: 2022-01-13 19:43
 */
@Slf4j
@RestController
@Api(tags="demo")
public class DemoController {


    /**
     * 测试注解字典
     *
     * @return
     */
    @TranslationDict({@FieldParam(dictType = "CUSTOMER_SEX", targetField = "sex"),
                      @FieldParam(dictType = "CUSTOMER_STATUS", targetField = "status", targetFieldValueClazz = Integer.class)})
    @GetMapping("/common/dict")
    @ApiOperation(value = "测试字典转义")
    public AjaxResult test1() {
        //接收到请求时间
        Long startTime = System.currentTimeMillis();
        List result = this.getResult();
        //处理完请求时间
        Long endTime = System.currentTimeMillis();
        log.info("The request takes {}ms", endTime - startTime);
        return new AjaxResult().success(result);
    }

    private List getResult() {
        List demos = new ArrayList<>();
        Demo demo = new Demo("张三", "1,2", 1);
        Demo demo2 = new Demo("李四", "2,1", 2);
        demos.add(demo);
        demos.add(demo2);

        for (int i = 0; i < 5; i++) {
            demos.add(new Demo("张三" + i, "1", 1));
        }
        return demos;
    }

}
